package br.elsa.survey.services.impl.tests;


import static org.mockito.Mockito.*;

import javax.enterprise.event.Event;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import br.elsa.survey.dao.SurveyDao;
import br.elsa.survey.domain.survey.Survey;
import br.elsa.survey.services.events.SurveyCreatedEvent;
import br.elsa.survey.services.impl.SurveyServiceBean;

public class SurveyServiceBeanTest {

	private SurveyServiceBean surveyServiceBean;
	
	@Mock
	private SurveyDao surveyDao;

	@Mock
	private Event<SurveyCreatedEvent> surveyCreatedEvent;
	
	@Mock
	private Survey survey;
	
	@Before
	public void setUp() throws Exception {
		
		MockitoAnnotations.initMocks(this);
		this.surveyServiceBean = new SurveyServiceBean(surveyDao, surveyCreatedEvent);
	}

	@Test
	public void createShouldCallSurveyDaoInsertMethodAndFireSurveyCreatedEventInThisOrder() {
		
		surveyServiceBean.create(survey);
		
		InOrder inOrder = inOrder(surveyDao, surveyCreatedEvent);
		inOrder.verify(surveyDao, times(1)).insert(survey);
		inOrder.verify(surveyCreatedEvent, times(1)).fire(any(SurveyCreatedEvent.class));
	}
}
